﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq.SqlClient;

namespace Hired
{
    /*  Jobseeker is linked to JobseekerAccount.
     *  In other words, 1 Jobseeker belongs to 1 JobseekerAccount.  */
    public class DBJobseeker
    {
        //add a Jobseeker method is with addJobseekerAccount method
        //search for a jobseeker is in searchJobseekerAccount method

        //retrieve Jobseeker
        public static Jobseeker RetrieveJobseeker(string jAccountID) 
        {
            Jobseeker jobseeker = new Jobseeker();
            using (hireddbEntities db = new hireddbEntities()) {
                jobseeker =
                    (from a in db.Jobseekers
                    where a.JAccountID == jAccountID
                    select a).First();
            }
            return jobseeker;
        }

        // update Jobseeker
        public static Boolean UpdateJobseeker(Jobseeker js) {
            try
            {
                using (hireddbEntities db = new hireddbEntities())
                {
                    Jobseeker jobseekerToUpdate = RetrieveJobseeker(js.JAccountID);
                    db.Attach(jobseekerToUpdate);
                    jobseekerToUpdate.Address = js.Address;
                    jobseekerToUpdate.CountryOfResidence = js.CountryOfResidence;
                    jobseekerToUpdate.DateOfBirth = js.DateOfBirth;
                    jobseekerToUpdate.EducationLevel = js.EducationLevel;
                    jobseekerToUpdate.FirstName = js.FirstName;
                    jobseekerToUpdate.Gender = js.Gender;
                    jobseekerToUpdate.HomeNumber = js.HomeNumber;
                    jobseekerToUpdate.ImageAddress = js.ImageAddress;
                    jobseekerToUpdate.LastName = js.LastName;
                    jobseekerToUpdate.MobileNumber = js.MobileNumber;
                    jobseekerToUpdate.Nationality = js.Nationality;
                    jobseekerToUpdate.PostalCode = js.PostalCode;
                    jobseekerToUpdate.PreviousEducationalInstitute = js.PreviousEducationalInstitute;
                    jobseekerToUpdate.CurrentEmployment = js.CurrentEmployment;
                    jobseekerToUpdate.Specialization = js.Specialization;
                    jobseekerToUpdate.PreviousEmployment = js.PreviousEmployment;
                    jobseekerToUpdate.ResumeAddress = js.ResumeAddress;
                    jobseekerToUpdate.WebsiteURL = js.WebsiteURL;

                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        

    }
}